# -*- mode: python; coding: utf-8; -*-
##--------------------------------------------------------------------------##
##
## Copyright (C) 1998-2003 Markus Oberhumer <markus@oberhumer.com>
## Copyright (C) 2003 Mt. Hood Playing Card Co.
## Copyright (C) 2005-2010 Skomoroh <skomoroh@users.sourceforge.net>
## Copyright (C) 2010-2013 Jeremy Austin-Bardo <tjaustinbardo@gmail.com>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.
##
##--------------------------------------------------------------------------##
"""
"""
from .. import formlib as layout

LEFT, RIGHT = layout.LEFT, layout.RIGHT


class SamuriLayout(layout.Layout):
    """
    static block:
      - foundations [E W]. Vert SUITS. max 6 cols.
      - rows [N] `_offset` if `playcards`. `ncols` wide.
      - talon [S].
      - waste [E] talon. `wastecards` ignored.

    :CVariables:
        _offset: func
          .. dict('ycards': playcards)

          Margin and offset is below piles.
    """
    _offset = lambda self, cards: {'ycards': cards}

    def create(self, rows, ncols=None, playcards=16, bases=None,
               texts=True, **kw):
        """
        create(rows[, ncols=rows, playcards=16, bases=suits * decks,
               texts=True]) -> None

        :Parameters:
          rows : int
            Num of `s.rows` to include.

          ncols : int
            Num of horz piles before starting new row. Default `ROWS`.

          playcards : int
            Num of possible cards as margin on each pile on `s.rows`. A value
            of 0 sets no offset and a value greater sets an offset. Default
            `16`.

          bases : tuple | list
            Value of each `suit` capabilty on `s.foundations`. Len is num of
            piles to include. Default `SUITS * DECKS`.

          texts : bool
            Whether to include num cards text label for `s.talon` and possible
            `s.waste`. Default `True`.

          align : LEFT | RIGHT
            Dynamic placement of `s.talon`, possible `s.waste`, and possible
            `s.reserves`. `s.foundations` placement is opposite side. Default
            `LEFT`
        """
        l, s = self, self.s
        ncols = ncols or rows
        bases = bases if type(bases) in (list, tuple) else l.SUITS
        bases.sort()
        ix = l.size.width + l.XM
        hf_rows = len(bases) / 2
        # W half vert foundations
        l._set_horz_foundations(x=ix, y=l.YM, nrows=l.NDECKS,
                                bases=bases[:hf_rows])
        l._set_rows(x=l.size.width + l.XM, y=l.YM, rows=rows,
                    ncols=ncols, **l._offset(playcards))
        l._set_horz_foundations(x=l.size.width + l.XM, y=l.YM, nrows=l.NDECKS,
                                bases=bases[hf_rows:])
        dx, dy = (l.size.width + l.XS) / 2, l.size.height - l.YS
        l._set_horz_talon(x=dx, y=l.YM + dy, texts=texts, align=LEFT,
                          anchor='s', wastecards=0)
        s['talon'].set_rounds(anchor='ss' if l._has_waste else 'e')